import 'package:flutter/material.dart';

class TextAvatarAnimation extends StatelessWidget {
  final double backgroundWidth;
  final String text;
  final Color color;
  final Icon icon;
  final EdgeInsets endEdgeInsets;

  TextAvatarAnimation(
      {Key key,
      this.controller,
      this.backgroundWidth,
      this.text,
      this.icon,
      this.color,
      this.endEdgeInsets})
      : padding = new EdgeInsetsTween(
          begin: const EdgeInsets.all(4.0),
          end: endEdgeInsets,
        )
            .animate(
          new CurvedAnimation(
            parent: controller,
            curve: new Interval(
              0.0,
              1.0,
              curve: Curves.ease,
            ),
          ),
        ),
        super(key: key);

  final Animation<double> controller;
  final Animation<EdgeInsets> padding;

// This function is called each the controller "ticks" a new frame.
// When it runs, all of the animation's values will have been
// updated to reflect the controller's current value.
  Widget _buildAnimation(BuildContext context, Widget child) {
    Column column = new Column(
      mainAxisSize: MainAxisSize.min, //make column not expand
      children: <Widget>[
        new Container(
          alignment: Alignment.center,
          height: 20.0,
          width: this.backgroundWidth,
          decoration: new BoxDecoration(
              color: Colors.black,
              borderRadius: new BorderRadius.all(new Radius.circular(10.0))),
          child: new Text(
            this.text,
            style: new TextStyle(
                inherit: false,
                color: Colors.white,
                fontSize: 14.0,
                fontWeight: FontWeight.normal),
          ),
        ),
        new SizedBox(
          height: 4.0,
        ),
        new GestureDetector(
          child: new CircleAvatar(
            radius: 24.0,
            backgroundColor: color,
            child: this.icon,
          ),
        ),
      ],
    );

    Container container = new Container(
        alignment: Alignment.bottomCenter,
        padding: padding.value,
        child: column);

    return container;
  }

  @override
  Widget build(BuildContext context) {
    return new AnimatedBuilder(
      builder: _buildAnimation,
      animation: controller,
    );
  }
}
